package com.yicheng.statistics.common

import java.util.Date

import com.yicheng.statistics.common.RTAModel._
import scala.concurrent.Future
import slick.jdbc.GetResult


/**
  * created by WangQian on 15/12/20.
  */

trait RTARepository{this: RTADBCompoent =>
  import driver.api._

  /**
    * 分析组集合
    */
  implicit val getAnalyseGroupResult = GetResult(u => AnalyseGroup(u.<<,u.<<,u.<<,u.<<?,u.<<?, u.<<))

  /** 根据设备获得分析组集合
    * @param deviceId 设备Id
    * @param deviceTypeId 设备类型Id
    * @return Seq[AnalyseGroup] 分析组集合
    */
  def getAnalyseGroupsByDevice(deviceId:String,deviceTypeId: Int):Future[Seq[AnalyseGroup]] = {
    db.run(sql"""SELECT a.*,ai.PlatformAlarmTypeID FROM etent.bi_analysegroups a
                  INNER JOIN etent.bi_analysegroups_vehicle b ON a.ID = b.AnalyseGroupsID
                  INNER JOIN etbasedata.pub_vehicle c ON b.VehicleID = c.ID
                  INNER JOIN etbasedata.pub_tbox d on c.TboxID = d.ID
                  INNER JOIN etent.bi_analyse_info ai ON a.AnalyseID = ai.id
                  WHERE d.DeviceID = $deviceId and c.IsDeleted = 0 and d.IsDeleted = 0
                  and d.DeviceType = $deviceTypeId """.as[AnalyseGroup])
  }

  /** 根据设备获得分析组集合
    * @param deviceId 设备Id
    * @param deviceTypeId 设备类型Id
    * @return Seq[AnalyseGroup] 分析组集合
    */
  def getAnalyseGroupsByRearviewMirror(deviceId:String,deviceTypeId: Int):Future[Seq[AnalyseGroup]] = {
    db.run(sql"""SELECT a.* FROM etent.bi_analysegroups a
                 INNER JOIN etent.bi_analysegroups_vehicle b ON a.ID = b.AnalyseGroupsID
                 INNER JOIN etbasedata.pub_vehicle c ON b.VehicleID = c.ID
                 INNER JOIN etbasedata.pub_rearview_mirror d on c.RearviewMirrorID = d.ID
                 WHERE d.DeviceID = $deviceId and c.IsDeleted = 0 and d.IsDeleted = 0
                 and d.IDType = $deviceTypeId """.as[AnalyseGroup])
  }

  /**
    * 超速报警分析设置集合
    */
  implicit val getVehicleSpeedSettingsResult = GetResult(u => VehicleSpeedSetting(u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<?,
    u.<<,u.<<,u.<<,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获得超速报警分析设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleSpeedSetting] 超速报警分析设置集合
    */
  def getVehicleSpeedSettings(analyseGroupsID:Long): Future[Seq[VehicleSpeedSetting]] = {
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 speedThreshold,timeThreshold,analyseType,name,earlyCmdContent,nightDriveBeginTime,nightDriveEndTime,
                 nightSpeedPercent,earlyWarningThreshold,createUserID,createUnitID,createDatetime,alarmMobile,openAlarmMobile
                 FROM etent.bi_set_vehicle_speed  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleSpeedSetting])
  }
  
  /**
   * 根据车辆id获得对应的超速分析组集合
   */
  def getVechicleSpeedSettingByID(deviceID:Long) : Future[Seq[VehicleSpeedSetting]] = {
    db.run(sql"""SELECT svs.id,svs.analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 speedThreshold,timeThreshold,analyseType,name,earlyCmdContent,nightDriveBeginTime,nightDriveEndTime,
                 nightSpeedPercent,earlyWarningThreshold,createUserID,createUnitID,createDatetime,alarmMobile,openAlarmMobile
                  FROM etent.bi_analysegroups_vehicle av
                  INNER JOIN etent.bi_analysegroups ag ON av.AnalyseGroupsID = ag.ID
                  INNER JOIN etent.bi_analyse_info ai ON ag.AnalyseID = ai.ID
                  inner join etent.bi_set_vehicle_speed svs on av.AnalyseGroupsID = svs.AnalyseGroupsID 
                  INNER JOIN etbasedata.pub_vehicle c ON av.VehicleID = c.ID
                  INNER JOIN etbasedata.pub_tbox d ON c.TboxID = d.ID
                  WHERE d.DeviceID =$deviceID""".as[VehicleSpeedSetting])
  }

  /**
    * 怠速报警条件设置集合
    */
  implicit val getVehicleIdlingSettingsResult = GetResult(u => VehicleIdlingSetting(u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<?,u.<<,u.<<,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?))

  /**
    * 获得怠速报警条件设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleIdlingSetting] 怠速报警条件设置集合
    */
  def getVehicleIdlingSettings(analyseGroupsID:Long): Future[Seq[VehicleIdlingSetting]] = {
    db.run(sql"""SELECT id,name,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,
                 startTime,endTime,timeThreshold,speedThreshold,alarmMobile,createUserID,createDatetime,createUnitID
                 FROM etent.bi_set_vehicle_idling  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleIdlingSetting])
  }

  /**
    * 时间栅栏报警设置集合
    */
  implicit val getVehicleFenceSettingsResult = GetResult(u => VehicleFenceSetting(u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?))

  /**
    * 获得时间栅栏报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleFenceSetting] 时间栅栏报警设置集合
    */
  def getVehicleFenceSettings(analyseGroupsID:Long): Future[Seq[VehicleFenceSetting]] = {
    db.run(sql"""SELECT id,name,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,
                 startTime,endTime,timeThreshold,alarmMobile,createUserID,createDatetime,createUnitID
                 FROM etent.bi_set_vehicle_fence  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleFenceSetting])
  }

  /**
    * 电池电量低报警设置集合
    */
  implicit val getVehicleBatteryLowSettingsResult = GetResult(u => VehicleBatteryLowSetting(u.<<,u.<<?,u.<<,u.<<,
    u.<<,u.<<,u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获得电池电量低报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryLowSetting] 电池电量低报警设置集合
    */
  def getVehicleBatteryLowSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryLowSetting]] = {
    db.run(sql"""SELECT id,name,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,
                 startTime,endTime,batteryThreshold,alarmMobile,createUserID,createDatetime,createUnitID,openAlarmMobile
                 FROM etent.bi_set_vehicle_batterylow  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryLowSetting])
  }
  /**
    * 车辆电池压差报警设置集合
    */
  implicit val getVehicleBatteryYCSettingsResult = GetResult(u => VehicleBatteryYCSetting(u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<))

  /**
    * 获取车辆电池压差报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryYCSetting] 车辆电池压差报警设置集合
    */
  def getVehicleBatteryYCSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryYCSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,
                endTime,createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_yc  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryYCSetting])
  }

  /**
    * 电压差异报警条件设置集合
    */
  implicit val getVehicleBatteryDYCYSettingsResult = GetResult(u => VehicleBatteryDYCYSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获取电压差异报警条件设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryDYCYSetting] 电压差异报警条件设置集合
    */
  def getVehicleBatteryDYCYSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryDYCYSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,level1Lower,level1Upper,level2Lower,
                 level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,level5Lower,level5Upper,
                 level6Lower,level6Upper,unit,openAlarmMobile
                  FROM etent.bi_set_vehicle_battery_dycy  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryDYCYSetting])
  }

  /**
    * 单体过压报警设置集合
    */
  implicit val getVehicleBatteryDTGYSettingsResult = GetResult(u => VehicleBatteryDTGYSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获取单体过压报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryDTGYSetting] 单体过压报警设置集合
    */
  def getVehicleBatteryDTGYSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryDTGYSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_dtgy  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryDTGYSetting])
  }

  /**
    * 单体欠压报警条件设置集合
    */
  implicit val getVehicleBatteryDTQYSettingsResult = GetResult(u => VehicleBatteryDTQYSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?
    ,u.<<?,u.<<?,u.<<))

  /**
    * 获取单体欠压报警条件设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryDTQYSetting] 单体欠压报警条件设置集合
    */
  def getVehicleBatteryDTQYSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryDTQYSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime
                 ,endTime,createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_dtqy  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryDTQYSetting])
  }

  /**
    * 温差报警条件设置集合
    */
  implicit val getVehicleBatteryWCSettingsResult = GetResult(u => VehicleBatteryWCSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获取温差报警条件设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryWCSetting] 温差报警条件设置集合
    */
  def getVehicleBatteryWCSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryWCSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_wc  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryWCSetting])
  }

  /**
    * 温度过高报警条件设置集合
    */
  implicit val getVehicleBatteryWDGGSettingsResult = GetResult(u => VehicleBatteryWDGGSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获取温度过高报警条件设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryWDGGSetting] 温度过高报警条件设置集合
    */
  def getVehicleBatteryWDGGSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryWDGGSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_wdgg  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryWDGGSetting])
  }

  /**
    * 温感线异常报警设置集合
    */
  implicit val getVehicleBatteryWGXYCSettingsResult = GetResult(u => VehicleBatteryWGXYCSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获取温感线异常报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryWGXYCSetting] 温感线异常报警设置集合
    */
  def getVehicleBatteryWGXYCSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryWGXYCSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_wgxyc  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryWGXYCSetting])
  }

  /**
    * 绝缘过低报警设置集合
    */
  implicit val getVehicleBatteryJYGDSettingsResult = GetResult(u => VehicleBatteryJYGDSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?
    ,u.<<?,u.<<?,u.<<))

  /**
    * 获取绝缘过低报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryJYGDSetting] 绝缘过低报警设置集合
    */
  def getVehicleBatteryJYGDSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryJYGDSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_jygd  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryJYGDSetting])
  }

  /**
    * 充高放低报警设置集合
    */
  implicit val getVehicleBatteryCGFDSettingsResult = GetResult(u => VehicleBatteryCGFDSetting(u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<?,u.<<))

  /**
    * 获取充高放低报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatteryCGFDSetting] 充高放低报警设置集合
    */
  def getVehicleBatteryCGFDSettings(analyseGroupsID:Long): Future[Seq[VehicleBatteryCGFDSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_cgfd  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatteryCGFDSetting])
  }

  /**
    * SOC过低报警设置集合
    */
  implicit val getVehicleBatterySOCSettingsResult = GetResult(u => VehicleBatterySOCSetting(u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<?,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获取SOC过低报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleBatterySOCSetting] SOC过低报警设置集合
    */
  def getVehicleBatterySOCSettings(analyseGroupsID:Long): Future[Seq[VehicleBatterySOCSetting]] ={
    db.run(sql"""SELECT  id,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                 createUserID,createDatetime,createUnitID,name,alarmMobile,
                 level1Lower,level1Upper,level2Lower,level2Upper,level3Lower,level3Upper,level4Lower,level4Upper,
                 level5Lower,level5Upper,level6Lower,level6Upper,unit,openAlarmMobile
                 FROM etent.bi_set_vehicle_battery_soc  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleBatterySOCSetting])
  }

  /**
    * 离线报警设置集合
    */
  implicit val getVehicleOfflineSettingsResult = GetResult(u => VehicleOfflineSetting(u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<?,u.<<,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?))

  /**
    * 获得离线报警设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleOfflineSetting] 离线报警设置集合
    */
  def getVehicleOfflineSettings(analyseGroupsID:Long): Future[Seq[VehicleOfflineSetting]] = {
    db.run(sql"""SELECT id,name,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                  timeThreshold,alarmmobile,createUserID,createDatetime,createUnitID
                 FROM etent.bi_set_vehicle_offline  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleOfflineSetting])
  }

  /**
    * 疲劳驾驶分析设置集合
    */
  implicit val getVehicleTiredSettingsResult = GetResult(u => VehicleTiredSetting(
    u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
    u.<<?,u.<<?,u.<<))

  /**
    * 获得疲劳驾驶分析设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleTiredSetting] 疲劳驾驶分析设置集合
    */
  def getVehicleTiredSettings(analyseGroupsID:Long): Future[Seq[VehicleTiredSetting]] = {
    db.run(sql"""SELECT  id,name,analyseGroupsID,remindType,remindInterval,commandContent,analysePeriod,periodValue,startTime,endTime,
                  continuousRestTime,totalRestTime,effectiveRestTime,timeThreshold,earlyWarningThreshold,minDistance,nightTimeThreshold,
                  nightDriveBeginTime,nightDriveendTime,dayTiredTime,alarmmobile,createUserID,createDatetime,
                  createUnitID,openAlarmMobile
                 FROM etent.bi_set_vehicle_tired  WHERE analyseGroupsID = $analyseGroupsID
                 ORDER BY createDatetime DESC """.as[VehicleTiredSetting])
  }

  /**
    * 进出区域分析设置集合
    */
  implicit val getVehicleInOutAreaSettingsResult = GetResult(u => VehicleInOutAreaSetting(
    u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<?,u.<<,u.<<,Option(CustomArea(u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,
      u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?)),u.<<,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 进出区域分析设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleInOutAreaSetting] 进出区域分析设置集合
    */
  def getVehicleInOutAreaSettings(analyseGroupsID:Long): Future[Seq[VehicleInOutAreaSetting]] = {
    db.run(sql"""SELECT a.id,a.name,a.analyseGroupsID,a.remindType,a.remindInterval,a.commandContent,a.analysePeriod,a.periodValue,a.startTime,a.endTime,
                  b.id,b.customcode,b.name,b.maplayerid,b.drawingType,b.lon,b.lat,b.lonlat,b.originlnglat,b.mapiconid,b.maptype,b.workunitid,
                  b.address,b.namecolor,b.area,b.areacolor,b.radius,b.remark,
                  a.timeThreshold,a.alarmType,a.alarmMobile,a.createUserID,a.createDatetime,a.createUnitID,a.openAlarmMobile
                  FROM etent.bi_set_area_inout  a
                  LEFT JOIN etent.ent_custommap b on a.coverageGroupsID = b.id
                  WHERE a.analyseGroupsID = $analyseGroupsID ORDER BY a.createDatetime DESC """.as[VehicleInOutAreaSetting])

  }

  /**
    * 进出地点分析设置集合
    */
  implicit val getVehicleInOutLocaleSettingResult = GetResult(u =>
    VehicleInOutLocaleSetting(u.<<,u.<<?,u.<<,u.<<,u.<<,u.<<,u.<<?,u.<<,u.<<,
      Option(CustomPoint(u.<<,u.<<?,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?,u.<<?))
      ,u.<<,u.<<,u.<<?,u.<<,u.<<?,u.<<?,u.<<?,u.<<?,u.<<))

  /**
    * 获得进出地点分析设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleInOutLocaleSetting] 进出地点分析设置集合
    */
  def getVehicleInOutLocaleSettings(analyseGroupsID:Long): Future[Seq[VehicleInOutLocaleSetting]] = {

    db.run(sql"""SELECT a.id,a.name,a.analyseGroupsID,a.remindType,a.commandContent,a.analysePeriod,a.periodValue,
              a.startTime,a.endTime,
              b.id,b.customcode,b.name,b.maplayerid,b.lon,b.lat,b.originlongitude,b.originlatitude,b.mapiconid,
              b.maptype,b.workunitid,b.address,b.namecolor,b.area,b.areacolor,b.radius,b.remark,
              a.coverageRange,a.timeThreshold,a.remindInterval,a.alarmType,a.createUserID,
              a.createDatetime,a.createUnitID,a.alarmMobile,a.openAlarmMobile
              FROM etent.bi_set_locale_inout a
              LEFT JOIN etent.ent_custommappoint b on a.coverageGroupsID = b.id
              WHERE a.analyseGroupsID = $analyseGroupsID ORDER BY a.createDatetime DESC """.as[VehicleInOutLocaleSetting])
  }

  /**
    * 道路偏移设置集合
    */
  implicit val getVehicleRoadSettingsResult = GetResult(u => VehicleRoadSetting(u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,
    u.<<,u.<<,u.<<,u.<<,Option(CustomLine(u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,
      u.<<,u.<<,u.<<,u.<<,u.<<,u.<<)),u.<<,u.<<,u.<<,u.<<))

  /**
    * 获得道路偏移设置集合
    * @param analyseGroupsID 分析组Id
    * @return Seq[VehicleRoadSetting] 道路偏移设置集合
    */
  def getVehicleRoadSettings(analyseGroupsID:Long): Future[Seq[VehicleRoadSetting]] = {

    db.run(sql"""SELECT a.id,a.name,a.analyseGroupsID,a.remindType,a.remindInterval,a.commandContent,
                a.analysePeriod,a.periodValue,a.startTime,a.endTime,a.validDistance,a.allowLeaveMaxTime,
                b.id,b.name,b.nameColor,b.customCode,b.workUnitID,b.customType,b.strokeColor,b.strokeWeight,b.areaColor,
                b.qdlongitude,b.qdlatitude,b.zdlongitude,b.zdlatitude,b.imgUrl,b.zoom,b.shortName,b.startPoint,
                b.endPoint,b.mileage,b.remark,a.alarmType,a.createUserID,a.createDatetime,a.createUnitID
                FROM etent.bi_set_vehicle_road a
                LEFT JOIN etent.ent_line b on a.coverageGroupsID = b.id
                WHERE a.analyseGroupsID = $analyseGroupsID ORDER BY a.createDatetime DESC """.as[VehicleRoadSetting])

  }

  /**
    * 自定义线对应点集合
    */
  implicit val getCustomLinePointsResult = GetResult(u => CustomLinePoint(u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<,u.<<))

  /**
    * 获得自定义线对应点集合
    * @param lineID 线路Id
    * @return
    */
  def getCustomLinePoints(lineID:Long): Future[Seq[CustomLinePoint]] = {
    db.run(sql"""SELECT id,lineId,longitude,latitude,originlongitude,originlatitude,flag,zoom
              FROM etent.ent_linepoint WHERE lineID = $lineID """.as[CustomLinePoint])
  }

  def parseDate(date:Date): java.sql.Timestamp = {
      new java.sql.Timestamp(date.getTime)
  }

}

object HTADB extends RTARepository with RTADBCompoent

